package cn.dt.ymcc.service.impl;

import cn.dt.ymcc.service.ITokenService;
import cn.dt.ymcc.util.StrUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class TokenServiceImpl implements ITokenService {
    @Autowired
    private RedisTemplate<Object,Object> redisTemplate;
    /**
     * 生成token给前端
     * 1.token的key是loginId+courseId
     * 2.token串用工具类生成随机10位
     * 3.存redis
     * @param courseId
     * @return
     */
    @Override
    public String createToken(String courseId) {
        Long loginId = 1L;
        String key = loginId+":"+courseId;
        String token = StrUtils.getComplexRandomString(10);
        redisTemplate.opsForValue().set(key,token,10, TimeUnit.MINUTES);
        return token;
    }
}
